library(tidyverse)
library(magrittr)
library(lubridate)
library(scales)
library(matrixStats)
library(ggrepel)
library(broom)
library(glue)
library(jsonlite)
library(rvest)
library(RCurl)
library(pander)
library(plotly)
library(cowplot)
library(QuantTools)
library(ggfortify)
library(readxl)
library(httr)
panderOptions("big.mark", ",")
panderOptions("table.split.table", Inf)
panderOptions("table.style", "rmarkdown")
panderOptions("missing", "")
theme_set(theme_bw())
shiftAxisLabel <- function(x, k = 2){
  x$x$layout$annotations[[2]]$x <- x$x$layout$annotations[[2]]$x*k
  x$x$layout$margin$l <- x$x$layout$margin$l*k
  x
}
# Handle updates between 1am & 12pm
dt <- Sys.Date()
if (as.numeric(format(Sys.time(), "%H")) < 11){
  dt <- Sys.Date() - 1
}
auStates <- c(
  ACT = "Australian Capital Territory",
  QLD = "Queensland",
  NSW = "New South Wales",
  VIC = "Victoria",
  SA = "South Australia",
  WA = "Western Australia",
  NT = "Northern Territory",
  TAS = "Tasmania"
)

Data Sources

confirmed <- url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv") %>%
    read_csv() %>%
    pivot_longer(
        cols = ends_with("20"),
        names_to = "date",
        values_to = "confirmed"
    )  %>%
    mutate(
        date = str_replace_all(
            date, "(.+)/(.+)/(.+)", "20\\3-\\1-\\2"
        ) %>%
            ymd()
    ) %>%
    dplyr::rename(
        Country = `Country/Region`
    ) %>%
    dplyr::filter(
        !is.na(confirmed),
        Country == "Australia"
    ) %>%
  dplyr::select(-Lat, -Long)
guardData <- fromJSON("https://interactive.guim.co.uk/docsdata/1q5gdePANXci8enuiS4oHUJxcxC13d6bjMRSicakychE.json")
altAU <- guardData$sheets$updates %>% 
  as_tibble() %>% 
  mutate(
    `Province/State` = auStates[State], 
    Country = "Australia", 
    Date = parse_date_time(Date, orders = "%d/%m/%Y") %>% ymd()
  ) %>% 
  dplyr::select(`Province/State`, Country, date = Date, confirmed = `Cumulative case count`) %>% 
  mutate(confirmed = as.numeric(confirmed)) %>%
  arrange(`Province/State`, date) %>%
  tidyr::complete(`Province/State`, Country, date) %>%
  group_by(`Province/State`) %>%
  fill(confirmed)  %>%
  dplyr::filter(!is.na(confirmed))  %>%
  ungroup()
# # Add the data, with the Guardian API being preferentialy selected
# confirmed %<>%
#   mutate(source = "JHU") %>%
#   bind_rows(
#     mutate(altAU, source = "API")
#   ) %>%
#   arrange(
#     date, `Province/State`, source
#   ) %>%
#   distinct(`Province/State`, Country, date, .keep_all = TRUE) %>%
#   dplyr::select(-source)
latestAU <- list()
# The NSW data for JHU is nearly always wrong. Just get rid of it
confirmed <- dplyr::filter(confirmed, `Province/State` != "New South Wales") %>%
  bind_rows(
    "https://covidlive.com.au/report/daily-cases/nsw" %>%
      read_html() %>%
      html_nodes("body") %>%
      xml_find_all("//table[contains(@class, 'DAILY-CASES')]") %>% 
      html_table() %>%
      .[[1]] %>%
      as_tibble() %>%
      dplyr::select(date = DATE, confirmed = CASES) %>%
      separate(date, into = c("day", "month")) %>%
      mutate(
        year = "2020",
        date = paste(year, month, day, sep = "-"),
        date = parse_date_time(date, orders = "%Y-%B-%d"),
        date = ymd(date),
        confirmed = str_remove_all(confirmed, ","),
        confirmed = as.numeric(confirmed),
        `Province/State` = "New South Wales",
        Country = "Australia"
      ) %>%
      dplyr::select(any_of(colnames(confirmed))) %>%
      arrange(date) %>%
      dplyr::filter(date <= dt)
  )
nswUrl <- "https://www.nsw.gov.au/covid-19"
nswTotal <- fromJSON("https://nswdac-covid-19-postcode-heatmap.azurewebsites.net/datafiles/usecase2.json")$data %>%
  as_tibble() %>%
  mutate(Total = cumsum(Cases)) 
nswAct <- fromJSON("https://nswdac-covid-19-postcode-heatmap.azurewebsites.net/datafiles/active_cases.json")$data %>%
  as_tibble() %>%
  summarise_at(vars(starts_with("Day")), sum) %>%
  pivot_longer(everything(), names_to = "Day", values_to = "Active") %>%
  mutate(Day = str_remove(Day, "Day") %>% as.numeric()) %>%
  arrange(Day) %>%
  mutate(
    date = tail(nswTotal$notification_date, 1) %>% 
      paste0("-2020") %>% 
      parse_date("%d-%b-%Y") %>% 
      ymd() %>%
      subtract(Day)
  )
nswAll <- fromJSON("https://nswdac-covid-19-postcode-heatmap.azurewebsites.net/datafiles/stats.json")$data %>%
   as_tibble() %>%
   mutate(
     date = tail(nswTotal$notification_date, 1) %>% 
       paste0("-2020") %>% 
       parse_date("%d-%b-%Y") %>% 
       ymd()
   ) %>%
   left_join(nswAct) %>%
   mutate(Recovered = Cases - Deaths - Active)
latestAU$NSW <- tibble(
  State = "New South Wales",
  date = dt,
  confirmed = nswAll$Cases,
  deaths = nswAll$Deaths,
  recovered = nswAll$Recovered,
  tested = nswAll$Tested
)
# The NSW data for JHU is nearly always wrong. Just get rid of it
confirmed <- dplyr::filter(confirmed, `Province/State` != "Queensland") %>%
  bind_rows(
    "https://covidlive.com.au/report/daily-cases/qld" %>%
      read_html() %>%
      html_nodes("body") %>%
      xml_find_all("//table[contains(@class, 'DAILY-CASES')]") %>% 
      html_table() %>%
      .[[1]] %>%
      as_tibble() %>%
      dplyr::select(date = DATE, confirmed = CASES) %>%
      separate(date, into = c("day", "month")) %>%
      mutate(
        year = "2020",
        date = paste(year, month, day, sep = "-"),
        date = parse_date_time(date, orders = "%Y-%B-%d"),
        date = ymd(date),
        confirmed = str_remove_all(confirmed, ","),
        confirmed = as.numeric(confirmed),
        `Province/State` = "Queensland",
        Country = "Australia"
      ) %>%
      dplyr::select(any_of(colnames(confirmed))) %>%
      arrange(date) %>%
      dplyr::filter(date <= dt)
  )
qldUrl <- "https://covidlive.com.au/qld" 
qldBody <- qldUrl %>% 
    read_html() %>% 
    html_nodes("body") 
qldTable <- qldBody %>%
  xml_find_all("//table[contains(@class, 'DAILY-SUMMARY')]") %>% 
  html_table() %>%
  .[[1]] %>% 
  dplyr::filter(!str_detect(CATEGORY, "Last Updated")) %>%
  mutate(
    TOTAL = str_remove_all(TOTAL, ",") %>% as.numeric
  )
latestAU$QLD <- tibble(
  State = "Queensland",
  date = dt,
  confirmed = qldTable %>%
      dplyr::filter(CATEGORY == "Cases") %>%
      pull(TOTAL),
  deaths =  qldTable %>%
      dplyr::filter(CATEGORY == "Deaths") %>%
      pull(TOTAL),
  recovered =  qldTable %>%
      dplyr::filter(CATEGORY == "Recoveries") %>%
      pull(TOTAL),
  tested = qldBody %>% 
      xml_find_all("//table[contains(@class, 'DAILY-TESTS')]") %>%
      html_table() %>% 
      .[[1]] %>% 
      mutate(TESTS = str_remove_all(TESTS, ",") %>% as.numeric) %>% 
      pull(TESTS) %>%
      max()
)
# The data for JHU is nearly always wrong. Just get rid of it
confirmed <- dplyr::filter(confirmed, `Province/State` != "Victoria") %>%
  bind_rows(
    "https://covidlive.com.au/report/daily-cases/vic" %>%
      read_html() %>%
      html_nodes("body") %>%
      xml_find_all("//table[contains(@class, 'DAILY-CASES')]") %>% 
      html_table() %>%
      .[[1]] %>%
      as_tibble() %>%
      dplyr::select(date = DATE, confirmed = CASES) %>%
      separate(date, into = c("day", "month")) %>%
      mutate(
        year = "2020",
        date = paste(year, month, day, sep = "-"),
        date = parse_date_time(date, orders = "%Y-%B-%d"),
        date = ymd(date),
        confirmed = str_remove_all(confirmed, ","),
        confirmed = as.numeric(confirmed),
        `Province/State` = "Victoria",
        Country = "Australia"
      ) %>%
      dplyr::select(any_of(colnames(confirmed))) %>%
      arrange(date) %>%
      dplyr::filter(date <= dt)
  )
vicUrl <- "https://covidlive.com.au/vic"
vicBody <- vicUrl %>% 
  read_html() %>% 
  html_nodes("body") 
vicTable <- vicBody %>%
  xml_find_all("//table[contains(@class, 'DAILY-SUMMARY')]") %>% 
  html_table() %>%
  .[[1]] %>% 
  dplyr::filter(
    !str_detect(CATEGORY, "Updated")
  ) %>%
  mutate(
    TOTAL = str_remove_all(TOTAL, ",") %>% as.numeric
  )
latestAU$VIC <- tibble(
  State = "Victoria",
  date = dt,
  confirmed = vicTable %>%
      dplyr::filter(CATEGORY == "Cases") %>%
      pull(TOTAL),
  deaths =  vicTable %>%
      dplyr::filter(CATEGORY == "Deaths") %>%
      pull(TOTAL),
  recovered =  vicTable %>%
      dplyr::filter(CATEGORY == "Recoveries") %>%
      pull(TOTAL),
  tested = vicBody %>% 
      xml_find_all("//table[contains(@class, 'DAILY-TESTS')]") %>%
      html_table() %>% 
      .[[1]] %>% 
      mutate(TESTS = str_remove_all(TESTS, ",") %>% as.numeric) %>% 
      pull(TESTS) %>%
      max()
)
# The SA data for JHU is nearly always wrong. Just get rid of it
confirmed <- dplyr::filter(confirmed, `Province/State` != "Western Australia") %>%
  bind_rows(
    "https://covidlive.com.au/report/daily-cases/wa" %>%
      read_html() %>%
      html_nodes("body") %>%
      xml_find_all("//table[contains(@class, 'DAILY-CASES')]") %>% 
      html_table() %>%
      .[[1]] %>%
      as_tibble() %>%
      dplyr::select(date = DATE, confirmed = CASES) %>%
      separate(date, into = c("day", "month")) %>%
      mutate(
        year = "2020",
        date = paste(year, month, day, sep = "-"),
        date = parse_date_time(date, orders = "%Y-%B-%d"),
        date = ymd(date),
        `Province/State` = "Western Australia",
        Country = "Australia"
      ) %>%
      dplyr::select(any_of(colnames(confirmed))) %>%
      arrange(date) %>%
      dplyr::filter(date <= dt)
  )
waUrl <- "https://covidlive.com.au/wa" 
waBody <- waUrl %>% 
  read_html() %>% 
  html_nodes("body") 
waTable <- waBody %>%
  xml_find_all("//table[contains(@class, 'DAILY-SUMMARY')]") %>% 
  html_table() %>%
  .[[1]] %>% 
  dplyr::filter(
    !str_detect(CATEGORY, "Last Updated")
  ) %>%
  mutate(
    TOTAL = str_remove_all(TOTAL, ",") %>% as.numeric
  )
latestAU$WA <- tibble(
  State = "Western Australia",
  date = dt,
  confirmed = waTable %>%
      dplyr::filter(CATEGORY == "Cases") %>%
      pull(TOTAL),
  deaths =  waTable %>%
      dplyr::filter(CATEGORY == "Deaths") %>%
      pull(TOTAL),
  recovered =  waTable %>%
      dplyr::filter(CATEGORY == "Recoveries") %>%
      pull(TOTAL),
  tested = waBody %>% 
      xml_find_all("//table[contains(@class, 'DAILY-TESTS')]") %>%
      html_table() %>% 
      .[[1]] %>% 
      mutate(TESTS = str_remove_all(TESTS, ",") %>% as.numeric) %>% 
      pull(TESTS) %>%
      max()
)
# The SA data for JHU is nearly always wrong. Just get rid of it
confirmed <- dplyr::filter(confirmed, `Province/State` != "South Australia") %>%
  bind_rows(
    "https://covidlive.com.au/report/daily-cases/sa" %>%
      read_html() %>%
      html_nodes("body") %>%
      xml_find_all("//table[contains(@class, 'DAILY-CASES')]") %>% 
      html_table() %>%
      .[[1]] %>%
      as_tibble() %>%
      dplyr::select(date = DATE, confirmed = CASES) %>%
      separate(date, into = c("day", "month")) %>%
      mutate(
        year = "2020",
        date = paste(year, month, day, sep = "-"),
        date = parse_date_time(date, orders = "%Y-%B-%d"),
        date = ymd(date),
        `Province/State` = "South Australia",
        Country = "Australia"
      ) %>%
      dplyr::select(any_of(colnames(confirmed))) %>%
      arrange(date) %>%
      dplyr::filter(date <= dt)
  )
saUrl <- "https://covidlive.com.au/sa" 
saBody <- saUrl %>% 
  read_html() %>% 
  html_nodes("body") 
saTable <- saBody %>%
  xml_find_all("//table[contains(@class, 'DAILY-SUMMARY')]") %>% 
  html_table() %>%
  .[[1]] %>% 
  dplyr::filter(
    !str_detect(CATEGORY, "Last Updated")
  ) %>%
  mutate(
    TOTAL = str_remove_all(TOTAL, ",") %>% as.numeric
  )
latestAU$SA <- tibble(
  State = "South Australia",
  date = dt,
  confirmed = saTable %>%
    dplyr::filter(CATEGORY == "Cases") %>%
    pull(TOTAL),
  deaths =  saTable %>%
    dplyr::filter(CATEGORY == "Deaths") %>%
    pull(TOTAL),
  recovered =  saTable %>%
    dplyr::filter(CATEGORY == "Recoveries") %>%
    pull(TOTAL),
  tested = saBody %>% 
    xml_find_all("//table[contains(@class, 'DAILY-TESTS')]") %>%
    html_table() %>% 
    .[[1]] %>% 
    mutate(TESTS = str_remove_all(TESTS, ",") %>% as.numeric) %>% 
    pull(TESTS) %>%
    max()
)
# The ACT data for JHU is nearly always wrong. Just get rid of it
confirmed <- dplyr::filter(confirmed, `Province/State` != "Australian Capital Territory") %>%
  bind_rows(
    "https://covidlive.com.au/report/daily-cases/act" %>%
      read_html() %>%
      html_nodes("body") %>%
      xml_find_all("//table[contains(@class, 'DAILY-CASES')]") %>% 
      html_table() %>%
      .[[1]] %>%
      as_tibble() %>%
      dplyr::select(date = DATE, confirmed = CASES) %>%
      separate(date, into = c("day", "month")) %>%
      mutate(
        year = "2020",
        date = paste(year, month, day, sep = "-"),
        date = parse_date_time(date, orders = "%Y-%B-%d"),
        date = ymd(date),
        `Province/State` = "Australian Capital Territory",
        Country = "Australia"
      ) %>%
      dplyr::select(any_of(colnames(confirmed))) %>%
      arrange(date) %>%
      dplyr::filter(date <= dt)
  )
actUrl <- "https://covidlive.com.au/act" 
actBody <- actUrl %>% 
  read_html() %>% 
  html_nodes("body") 
actTable <- actBody %>%
  xml_find_all("//table[contains(@class, 'DAILY-SUMMARY')]") %>% 
  html_table() %>%
  .[[1]] %>% 
  dplyr::filter(
    !str_detect(CATEGORY, "Last Updated")
  ) %>%
  mutate(
    TOTAL = str_remove_all(TOTAL, ",") %>% as.numeric
  )
latestAU$ACT <- tibble(
  State = "Australian Capital Territory",
  date = dt,
  confirmed = actTable %>%
      dplyr::filter(CATEGORY == "Cases") %>%
      pull(TOTAL),
  deaths =  actTable %>%
      dplyr::filter(CATEGORY == "Deaths") %>%
      pull(TOTAL),
  recovered =  actTable %>%
      dplyr::filter(CATEGORY == "Recoveries") %>%
      pull(TOTAL),
  tested = actBody %>% 
      xml_find_all("//table[contains(@class, 'DAILY-TESTS')]") %>%
      html_table() %>% 
      .[[1]] %>% 
      mutate(TESTS = str_remove_all(TESTS, ",") %>% as.numeric) %>% 
      pull(TESTS) %>%
      max()
)
# The SA data for JHU is nearly always wrong. Just get rid of it
confirmed <- dplyr::filter(confirmed, `Province/State` != "Tasmania") %>%
  bind_rows(
    "https://covidlive.com.au/report/daily-cases/tas" %>%
      read_html() %>%
      html_nodes("body") %>%
      xml_find_all("//table[contains(@class, 'DAILY-CASES')]") %>% 
      html_table() %>%
      .[[1]] %>%
      as_tibble() %>%
      dplyr::select(date = DATE, confirmed = CASES) %>%
      separate(date, into = c("day", "month")) %>%
      mutate(
        year = "2020",
        date = paste(year, month, day, sep = "-"),
        date = parse_date_time(date, orders = "%Y-%B-%d"),
        date = ymd(date),
        `Province/State` = "Tasmania",
        Country = "Australia"
      ) %>%
      dplyr::select(any_of(colnames(confirmed))) %>%
      arrange(date) %>%
      dplyr::filter(date <= dt)
  )
tasUrl <- "https://www.coronavirus.tas.gov.au/facts/cases-and-testing-updates"
tasTables <- tasUrl %>%
  read_html() %>%
  html_nodes("body") %>%
  xml_find_all("//table") %>%
  html_table() %>%
  # .[2:1] %>%
  .[c(4, 3)] %>%
  lapply(mutate, Number = str_remove_all(Number, "[^0-9]")) %>%
  lapply(mutate, Number  = as.numeric(Number))
latestAU$TAS <- tibble(
  State = "Tasmania",
  date = dt,
  confirmed = dplyr::filter(
     tasTables[[1]], 
     str_detect(`Cases in Tasmania`, "Total cases")
     )$Number,
  deaths = dplyr::filter(
     tasTables[[1]], 
     str_detect(`Cases in Tasmania`, "Deaths")
     )$Number,
  recovered = dplyr::filter(
    tasTables[[1]],
    `Cases in Tasmania` == "Recovered"
    )$Number,
  tested = dplyr::filter(
    tasTables[[2]],
    `Laboratory tests` == "Total laboratory tests"
    )$Number
)
# The SA data for JHU is nearly always wrong. Just get rid of it
confirmed <- dplyr::filter(confirmed, `Province/State` != "Northern Territory") %>%
  bind_rows(
    "https://covidlive.com.au/report/daily-cases/nt" %>%
      read_html() %>%
      html_nodes("body") %>%
      xml_find_all("//table[contains(@class, 'DAILY-CASES')]") %>% 
      html_table() %>%
      .[[1]] %>%
      as_tibble() %>%
      dplyr::select(date = DATE, confirmed = CASES) %>%
      separate(date, into = c("day", "month")) %>%
      mutate(
        year = "2020",
        date = paste(year, month, day, sep = "-"),
        date = parse_date_time(date, orders = "%Y-%B-%d"),
        date = ymd(date),
        `Province/State` = "Northern Territory",
        Country = "Australia"
      ) %>%
      dplyr::select(any_of(colnames(confirmed))) %>%
      arrange(date) %>%
      dplyr::filter(date <= dt)
  )
ntUrl <- "https://coronavirus.nt.gov.au/current-status"
ntTable <- suppressWarnings(
  ntUrl %>% 
    read_html() %>% 
    html_nodes("body") %>%
    xml_find_all("//div[contains(@class, 'covid-card-stats')]") %>% 
    html_text() %>% 
    str_remove_all("\r\n") %>% 
    str_split("  +") %>% 
    .[[1]] %>% 
    .[nchar(.) > 0] %>%
    str_remove_all(",") %>% 
    enframe(name = c()) %>% 
    mutate(
      num = !is.na(suppressWarnings(as.integer(value))),
      card = cumsum(num)
    ) %>%
    pivot_wider(id_cols = card, values_from = value, names_from = num, names_prefix = "num_") %>%
    mutate(
      num_FALSE = vapply(num_FALSE, paste, character(1), collapse = " "), 
      num_TRUE = vapply(num_TRUE, as.integer, integer(1))
    ) %>%
    dplyr::select(Total = num_TRUE, Category = num_FALSE)
)
latestAU$NT <- tibble(
  State = "Northern Territory",
  date = dt,
  confirmed = dplyr::filter(ntTable, str_detect(Category, "confirmed"))$Total,
  deaths = 0,
  recovered = dplyr::filter(ntTable, str_detect(Category, "recovered"))$Total,
  tested = dplyr::filter(ntTable, str_detect(Category, "tests"))$Total
)
latestAU %<>% 
  bind_rows() %>%
  mutate(Country = "Australia")
latestAU %>%
  dplyr::select(
    `Province/State` = State, Country, date, recovered
  ) %>%
  write_tsv(
    here::here(glue("recovered/recovered_{dt}.tsv"))
  )
confirmed %<>%
  bind_rows(
    dplyr::select(latestAU, any_of(colnames(.)), `Province/State` = State)
  ) %>%
  arrange(date) %>%
  mutate(f = paste(`Province/State`, Country, sep = "_")) %>%
  split(f = .$f) %>%
  lapply(mutate, confirmed = cummax(confirmed)) %>%
  bind_rows() %>%
  dplyr::select(-f) %>%
  arrange(Country, `Province/State`, date, desc(confirmed)) %>%
  dplyr::distinct(`Province/State`, Country, date, .keep_all = TRUE)
auRecTS <- list.files(here::here("recovered"), pattern = "rec.*tsv",full.names = TRUE) %>%
  lapply(read_tsv) %>%
  bind_rows() %>% 
  arrange(`Province/State`, date) %>%
  group_by(`Province/State`) %>%
  mutate(recovered = cummax(recovered))
recovered <- url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv") %>%
    read_csv() %>%
    pivot_longer(
        cols = ends_with("20"),
        names_to = "date",
        values_to = "recovered"
    )  %>%
    mutate(
        date = str_replace_all(
            date, "(.+)/(.+)/(.+)", "20\\3-\\1-\\2"
        ) %>%
            ymd()
    ) %>%
    dplyr::rename(
        Country = `Country/Region`
    ) %>%
    dplyr::select(-Lat, -Long) %>%
    dplyr::filter(Country == "Australia") %>%
    bind_rows(auRecTS) %>%
    group_by(
        `Province/State`, Country, date
    ) %>%
    summarise_at(vars(recovered), max) %>%
  ungroup()
# Now deal with any missing values from early in the day updates
recovered %<>% 
  expand(`Province/State`, Country, date) %>% 
  left_join(recovered) %>%
  mutate(recovered = na_locf(recovered))
deaths <- url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv") %>%
    read_csv() %>%
    pivot_longer(
        cols = ends_with("20"),
        names_to = "date",
        values_to = "deaths"
    )  %>%
    mutate(
        date = str_replace_all(
            date, "(.+)/(.+)/(.+)", "20\\3-\\1-\\2"
        ) %>%
            ymd()
    ) %>%
    dplyr::rename(
        Country = `Country/Region`
    ) %>%
    dplyr::filter(Country == "Australia") %>%
    dplyr::select(-Lat, -Long) %>%
    bind_rows(
        dplyr::select(latestAU, any_of(colnames(.)), `Province/State` = State)
    ) %>%
    arrange(date) %>%
    mutate(f = paste(`Province/State`, Country, sep = "_")) %>%
    split(f = .$f) %>%
    lapply(mutate, deaths = cummax(deaths)) %>%
    bind_rows() %>%
    dplyr::select(-f) %>%
    dplyr::distinct(`Province/State`, Country, date, .keep_all = TRUE) 
# Now deal with any missing values from early in the day updates
deaths %<>% 
  expand(`Province/State`, Country, date) %>% 
  left_join(deaths) %>%
  mutate(deaths = na_locf(deaths))

Data for confirmed cases, recoveries and fatalities was primarily sourced from Johns Hopkins University, using the datasets provided at https://github.com/CSSEGISandData/COVID-19. JHU data is now updated every 24 hours at approximately 3:30(UTC), which is about 1:00PM in Adelaide. As such no accurate, daily updates for international data can be produced until after that time. Importantly, dates associated with confirmed cases from this data source, may differ from dates associated with confirmed cases from Australian sources. For example, cases reported in the morning in Australia may be assigned to the previous day in US data sources.

Live hourly updates for Australia are available from https://covid-19-au.com/ for those who would like an up to the minute breakdown of confirmed cases. Numbers used for generation of this page are updated periodically throughout the day using values provided by individual states at NSW, QLD, VIC, WA, SA, TAS, ACT and the NT. Additional Australian data was obtained from The Guardian. Whilst dates from the Guardian are likely to be reported using the UK time-zone as a reference, this is still closer to Australian time zones than USA-based data from JHU.

Information on recovered cases has been difficult to accurately obtain due inconsistent methods for considering a case as recovered, and lack of reporting for these cases in many jurisdictions. In Australia, some states (e.g. NSW & QLD) have only begun releasing these figures in mid-April, whilst other states such as Victoria were releasing these numbers from mid-March.

International Data

International data and figures can be viewed here

Latest Australian Data

ausPops <- tribble(
  ~State, ~Population,
  "New South Wales",    8117976,
  "Victoria", 6629870,
  "Queensland", 5115451,
  "South Australia", 1756494,
  "Western Australia", 2630557,
  "Tasmania", 535500,
  "Northern Territory", 245562,
  "Australian Capital Territory", 428060
)

Australian State populations were taken from the ABS Website and were accurate in Sept 2019.

All state-level numbers were obtained from the following sources: NSW, QLD, VIC, WA, SA, TAS, ACT and the NT.

  • Using an estimated population size of 25,459,470, the total percentage of the Australian population confirmed as having been infected currently sits at 0.11%, or one person in every 917.
  • Within Victoria, that rises to one in every 326 having contracted the virus at some point
  • NSW Health made a significant change to their recovered cases when cases not tracked after 6 weeks were classified as recovered. An additional change was subsequently made such that active cases are now formally classed as locally acquired within the last 4 weeks. This change was implemented for data sources used here on 5th Sept 2020.
confirmed %>% 
  dplyr::filter(
    date >= sort(unique(date), decreasing = TRUE)[2]
  ) %>%
  bind_rows(
    group_by(., date) %>%
      summarise(
        confirmed = sum(confirmed)
      ) %>%
      mutate(
        `Province/State` = "Total"
      )
  ) %>%
  group_by(`Province/State`) %>%
  mutate(
    Increase = c(NA, diff(confirmed)),
    `% Increase` = c(NA, diff(confirmed)) / min(confirmed)
  ) %>%
  ungroup() %>%
  pivot_wider(
    id_cols = `Province/State`, 
    names_from = date, 
    values_from = c(confirmed, Increase, `% Increase`)
  ) %>%
  dplyr::select_if(function(x){sum(is.na(x)) <= 1}) %>%
  rename(State = `Province/State`) %>%
  rename_all(str_remove_all, pattern = "confirmed_") %>%
  rename_all(str_remove_all, pattern = "_2020.+") %>%
  left_join(
    dplyr::select(latestAU, State, deaths)
  ) %>%
  add_column(
    confirmed = .[[as.character(dt)]]
  ) %>%
  mutate_at(
    vars(confirmed, deaths),
    function(x){
      x[is.na(x)] <- sum(x, na.rm = TRUE)
      x
    }
  ) %>%
  left_join(
    auRecTS %>% 
      dplyr::filter(date == dt) %>% 
      dplyr::select(State = `Province/State`, recovered) %>%
      bind_rows(tibble(State = "Total", recovered = sum(.$recovered)))
  ) %>%
  mutate(
    `% Increase` = percent(`% Increase`, accuracy = 0.01),
    `Fatality Rate` = percent(deaths / confirmed, accuracy = 0.1),
    `Recovery Rate` = percent(recovered / confirmed, accuracy = 0.1),
    `Currently Active` = confirmed - recovered - deaths,
  ) %>%
  rename(
    Fatalities = deaths,
    Recovered = recovered
  ) %>%
  dplyr::select(
    State, starts_with("20"), ends_with("Increase"), starts_with("Fatal"), starts_with("Recov"), `Currently Active`
  ) %>%
  pander(
    justify = "lrrrrrrrrr",
    caption = paste(
      "*Confirmed cases, fatalities and recoveries reported by each state at time of preparation.",
      "Any states with unchanged, or decreasing confirmed cases may indicate delays with the automated data sources, such as health.gov.au or JHU, or that these states have not yet reported for the day.", 
      "Please note that some discrepancy with dates may occur due to automated data sources obtained different time zones, such as the USA, the UK and Australia.*"
    ),
    emphasize.strong.rows = nrow(.)
  )
Confirmed cases, fatalities and recoveries reported by each state at time of preparation. Any states with unchanged, or decreasing confirmed cases may indicate delays with the automated data sources, such as health.gov.au or JHU, or that these states have not yet reported for the day. Please note that some discrepancy with dates may occur due to automated data sources obtained different time zones, such as the USA, the UK and Australia.
State 2020-12-05 2020-12-06 Increase % Increase Fatalities Fatality Rate Recovered Recovery Rate Currently Active
Australian Capital Territory 117 117 0 0.00% 3 2.6% 113 96.6% 1
New South Wales 4,605 4,610 5 0.11% 55 1.2% 4,365 94.7% 190
Northern Territory 59 60 1 1.69% 0 0.0% 47 78.3% 13
Queensland 1,210 1,212 2 0.17% 6 0.5% 1,191 98.3% 15
South Australia 562 562 0 0.00% 4 0.7% 553 98.4% 5
Tasmania 230 230 0 0.00% 13 5.7% 215 93.5% 2
Victoria 20,347 20,347 0 0.00% 820 4.0% 19,526 96.0% 1
Western Australia 828 830 2 0.24% 9 1.1% 808 97.3% 13
Total 27,958 27,968 10 0.04% 910 3.3% 26,818 95.9% 240

Plot of Current Australian Values

ausStatsCap <- "*Current confirmed and recovered cases, along with fatalities for Australia only. Active cases are shown as confirmed cases excluding fatalities and those classed as recovered. Loess curves through all points are shown as continuous lines. Data is only shown from 1^st^ March 2020 as this was the date of the first recorded fatality in Australia. Recovered patient information was also sparse in the early stages of data collection, and as a result estimates of active infections will be a significant underestimate until 6^th^ April. In particular, QLD only began reporting recovered cases on this date. NSW followed a fortnight after this date and as such, only the most recent numbers can be considered as accurate. Below this plot, the same figures can be seen broken down by state.*"
ggplotly(
  confirmed %>%
    left_join(deaths) %>%
    left_join(recovered) %>%
    mutate_at(vars(confirmed, deaths, recovered), na_locf) %>%
    group_by(Country, date) %>%
    summarise_at(vars(confirmed, deaths, recovered), sum) %>%
    ungroup() %>%
    mutate_at(vars(confirmed, deaths, recovered), cummax) %>%
    mutate(active = confirmed - deaths - recovered) %>%
    pivot_longer(
      cols = c(active, confirmed, deaths, recovered),
      names_to = "Status",
      values_to = "Total"
    ) %>%
    arrange(Status, date) %>%
    dplyr::filter(date > ymd("2020-02-29")) %>%
    mutate(
      Status = str_to_title(Status),
      Status = str_replace_all(Status, "Deaths", "Fatal"),
      Status = factor(Status, levels = c("Fatal", "Recovered", "Active"))
    ) %>%
    dplyr::filter(Total > 0) %>%
    rename_all(str_to_title) %>%
    dplyr::filter(Status != "Confirmed") %>%
    ggplot(aes(Date, Total, fill = Status)) +
    geom_col() +
    geom_line(
      data = . %>%
        group_by(Date) %>%
        summarise(
          Total = sum(Total)
        ) %>%
        mutate(Status = "Confirmed"),
      colour = "blue"
    ) +
    scale_fill_manual(
      values = c(
        Active = rgb(0, 0, 0),
        Confirmed = rgb(0, 0.3, 0.7),
        Fatal = rgb(0.8, 0.2, 0.2),
        Recovered = rgb(0.2, 0.7, 0.4)
      )
    ) +
    scale_x_date(expand = expansion(c(0, 0.03))) +
    scale_y_continuous(expand = expansion(c(0, 0.05))) +
    labs("Total Cases")
)

Current confirmed and recovered cases, along with fatalities for Australia only. Active cases are shown as confirmed cases excluding fatalities and those classed as recovered. Loess curves through all points are shown as continuous lines. Data is only shown from 1st March 2020 as this was the date of the first recorded fatality in Australia. Recovered patient information was also sparse in the early stages of data collection, and as a result estimates of active infections will be a significant underestimate until 6th April. In particular, QLD only began reporting recovered cases on this date. NSW followed a fortnight after this date and as such, only the most recent numbers can be considered as accurate. Below this plot, the same figures can be seen broken down by state.

ggplotly(
  confirmed %>%
    left_join(deaths) %>%
    left_join(recovered) %>%
    mutate_at(vars(confirmed, deaths, recovered), na_locf) %>%
    rename(State = `Province/State`) %>%
    dplyr::filter(
      date > ymd("2020-03-19"),
    ) %>%
    arrange(date) %>%
    group_by(State) %>%
    mutate_at(
      vars(confirmed, recovered, deaths), cummax
    ) %>%
    ungroup() %>%
    left_join(ausPops) %>%
    mutate(active = confirmed - deaths - recovered) %>%
    pivot_longer(
      cols = c(confirmed, deaths, recovered, active),
      names_to = "status",
      values_to = "count"
    ) %>%
    dplyr::filter(
      count > 0,
      !(State %in% c("Queensland", "New South Wales") & status == "recovered" & date < ymd("2020-04-06")),
      !(State %in% c("South Australia") & status == "recovered" & date < ymd("2020-04-01")),    
      !(State %in% c("Tasmania") & status == "recovered" & date < ymd("2020-04-02")),
    ) %>%
    dplyr::filter(status != "confirmed") %>%
    mutate(
      rate = 1e6*count/Population,
      rate = round(rate, 2),
      status = str_replace(status, "deaths", "fatal") %>% str_to_title(),
      status = factor(status, levels = c("Fatal", "Recovered", "Active"))
    ) %>%
    rename_all(str_to_title) %>%
    ggplot(aes(Date, Rate, fill = Status, label = Count)) +
    geom_col() +
    geom_line(
      data = . %>%
        group_by(State, Date) %>%
        summarise(
          Rate = sum(Rate),
          Count = sum(Count)
        ) %>%
        mutate(Status = "Confirmed"),
      colour = "blue"
    ) +
    facet_wrap(~State, ncol = 4) + 
    scale_fill_manual(
      values = c(
        Active = rgb(0, 0, 0),
        Confirmed = rgb(0, 0.3, 0.7),
        Fatal = rgb(0.8, 0.2, 0.2),
        Recovered = rgb(0.2, 0.7, 0.4)
      )
    ) +
    scale_x_date(expand = expansion(c(0, 0.03))) +
    labs(y = "Rate (Cases / Million)")
)

Breakdown of individual states. Victorian recovered numbers began to be accurately reported from 22nd March, with other states gradually providing this information. NSW/QLD recovered cases have only recently begun being reported and up until the most recent dates, recovered/active values were very approximate for these states. The extreme drop for NSW active cases in early June is a function of the changed reporting strategy implemented by NSW Health.

Daily New Cases

ggplotly(
  confirmed %>%
    group_by(`Province/State`) %>%
    mutate(daily = c(0, diff(confirmed))) %>%
    ungroup() %>%
    dplyr::filter(confirmed > 0) %>%
    mutate(
      daily = case_when(
        daily < 0 ~ 0,
        daily >= 0 ~ daily
      )
    ) %>%
    bind_rows(
      group_by(., date) %>%
        summarise(daily = sum(daily)) %>%
        ungroup() %>%
        mutate(`Province/State` = "All States")
    ) %>%
    group_by(`Province/State`) %>%
    mutate(
      MA = round(sma(daily, 7), 2),
      MA2 = round(sma(daily, 14), 2),
      `Above Average` = MA > MA2
    ) %>%
    dplyr::filter(date > "2020-03-01") %>%
    ggplot(aes(date, daily)) +
    geom_col(
      aes(fill = `Above Average`, colour = `Above Average`),
      data = . %>% dplyr::filter(!is.na(`Above Average`)),
      width = 1/2
    ) +
    geom_line(aes(y = MA), colour = "blue") +
    geom_line(aes(y = MA2), colour = "black") +
    facet_wrap(~`Province/State`, scales = "free_y") +
    labs(
      x = "Date",
      y = "Daily New Cases",
      fill = "\nAbove\nAverage"
    ) +
    scale_fill_manual(values = c("white", rgb(1, 0.2, 0.2))) +
    scale_colour_manual(values = c("grey50", rgb(1, 0.2, 0.2))),
  tooltip = c(
    "date", "daily", "MA"
    )
)

Daily new cases for each state shown against the 7-day (blue) and 14-day (black) averages. Days which the 7-day average is above the 14-day average are highlighted in red.

Australian Fatality Rate

inc <- 6
icu <- 11
d <- 7
offset <- icu + d 
minDate <- "2020-04-10"
list(
  confirmed %>%
    group_by(date) %>%
    summarise_at("confirmed", sum) %>%
    left_join(
      deaths %>%
        group_by(date) %>%
        summarise_at("deaths", sum) 
    ) %>%
    dplyr::filter(
      date > minDate
    ) %>%
    mutate(
      fr = deaths / confirmed,
      type = "No Offset"
    ),
  confirmed %>%
    mutate(
      date = date + offset 
    ) %>%
    group_by(date) %>%
    summarise_at("confirmed", sum) %>%
    left_join(
      deaths %>%
        group_by(date) %>%
        summarise_at("deaths", sum) 
    ) %>%
    dplyr::filter(
      date > minDate
    ) %>%
    mutate(
      fr = deaths / confirmed,
      type = glue("Offset ({offset} days)")
    ) 
) %>%
  bind_rows() %>%
  ggplot(
    aes(date, fr, colour = type)
  ) +
  geom_line() +
  scale_x_date(
    expand = expansion(mult = 0, add = 0)
  ) +
  scale_y_continuous(label = percent) +
  labs(
    x = "Date",
    y = "Estimated Fatality Rate",
    colour = "Calculation"
  )
*Fatality rate for Australian cases as calculated using two methods.
Where no offset is included, the rate shown is simply the number of fatalities divided by the total number of reported cases on the same date.
When cases increase during a new outbreak, this will skew the fatality rate lower.
An alternative is to use an offset based on the fact the the median time from infection to symptom onset is 6 days, the median time from symptom onset to ICU admission is 11 days, and the median time from ICU admission to mortality is 7 days.
When using the offset, the fatality rate is calculated as the number of recorded fatalities on a given date, divided by by the number of cases from 18 days ago.
Whilst still flawed this may give a less biased estimate on the true fatality rate, and importantly, will always be higher than the alternative calculation.
The intial fatality rate spiked above 30% during the intial outbreak under the offset approach, and as such, data is only shown after 10 Apr, 2020.
All times used for estimation the offset were obtained from [here](https://wwwnc.cdc.gov/eid/article/26/6/20-0320_article)*

Fatality rate for Australian cases as calculated using two methods. Where no offset is included, the rate shown is simply the number of fatalities divided by the total number of reported cases on the same date. When cases increase during a new outbreak, this will skew the fatality rate lower. An alternative is to use an offset based on the fact the the median time from infection to symptom onset is 6 days, the median time from symptom onset to ICU admission is 11 days, and the median time from ICU admission to mortality is 7 days. When using the offset, the fatality rate is calculated as the number of recorded fatalities on a given date, divided by by the number of cases from 18 days ago. Whilst still flawed this may give a less biased estimate on the true fatality rate, and importantly, will always be higher than the alternative calculation. The intial fatality rate spiked above 30% during the intial outbreak under the offset approach, and as such, data is only shown after 10 Apr, 2020. All times used for estimation the offset were obtained from here

Current Growth Factor

n <- 14
cp <- glue(
  "*Growth factor for each State/Territory. 
  This value becomes volatile when daily new cases approach zero as is commonly observed in small populations, and at the end stages of an outbreak. 
  Given the multiple updates during the course of the day, values shown represent those up to the previous day.
  In order to try and minimise volatility a {n} day simple moving average was used, in contrast to the 5 day average as advocated [here](https://www.abc.net.au/news/2020-04-10/coronavirus-data-australia-growth-factor-covid-19/12132478).
  This enables assessment of the growth factor over an entire quarantine period.
  If no new cases are observed over this period, the value is not able to be calculated.
  The dashed vertical lines indicate the day most state borders were closed.*"
)
gf <- list(
  confirmed %>%
    dplyr::filter(Country == "Australia", date < dt) %>%
    arrange(date) %>%
    group_by(
      `Province/State`
    ) %>%
    mutate(
      new = c(0, diff(confirmed)),
      new_ma = sma(new, n)
    ) %>%
    dplyr::filter(confirmed > 0, !is.na(new_ma)) %>%
    mutate(
      R = c(NA, new_ma[-1] / new_ma[-n()]),
      R = case_when(
        is.nan(R) ~ NA_real_,
        !is.nan(R) ~ R
      )
    ) %>%
    ungroup() %>%
    arrange(`Province/State`),
  confirmed %>%
    dplyr::filter(Country == "Australia", date < dt) %>%
    arrange(date) %>%
    group_by(Country, date) %>%
    summarise_at(vars(confirmed), sum) %>%
    ungroup() %>%
    mutate(
      new = c(0, diff(confirmed)),
      new_ma = sma(new, n)
    ) %>%
    dplyr::filter(confirmed > 0, !is.na(new_ma)) %>%
    mutate(
      R = c(NA, new_ma[-1] / new_ma[-n()]),
      R = case_when(
        is.nan(R) ~ NA_real_,
        !is.nan(R) ~ R
      ),
      `Province/State` = "All States"
    ) %>%
    arrange(`Province/State`)
) %>%
  bind_rows() %>%
  dplyr::filter(date > ymd("2020-03-15")) %>%
  ggplot(aes(date, R, colour = `Province/State`)) +
  geom_ribbon(aes(ymin = 1, ymax = R), alpha = 0.1) +
  geom_hline(yintercept = 1) +
  geom_vline(
    xintercept = ymd("2020-03-22"),
    linetype = 2,
    colour = "grey30"
  ) +
  geom_label(
    aes(label = R),
    data = . %>%
      dplyr::filter(date == max(date)) %>%
      mutate(R = round(R, 2), date = date + 1),
    fill = rgb(1, 1, 1, 0.3),
    show.legend = FALSE,
    nudge_y = 0.3,
    size = 4
  ) +
  labs(
    x = "Date", y = "Growth Factor"
  ) +
  facet_wrap(~`Province/State`, scales = "free_x") +
  theme(legend.position = "none") +
  coord_cartesian(ylim = c(0.4, 2.1))
gf
*Growth factor for each State/Territory. 
This value becomes volatile when daily new cases approach zero as is commonly observed in small populations, and at the end stages of an outbreak. 
Given the multiple updates during the course of the day, values shown represent those up to the previous day.
In order to try and minimise volatility a 14 day simple moving average was used, in contrast to the 5 day average as advocated [here](https://www.abc.net.au/news/2020-04-10/coronavirus-data-australia-growth-factor-covid-19/12132478).
This enables assessment of the growth factor over an entire quarantine period.
If no new cases are observed over this period, the value is not able to be calculated.
The dashed vertical lines indicate the day most state borders were closed.*

Growth factor for each State/Territory. This value becomes volatile when daily new cases approach zero as is commonly observed in small populations, and at the end stages of an outbreak. Given the multiple updates during the course of the day, values shown represent those up to the previous day. In order to try and minimise volatility a 14 day simple moving average was used, in contrast to the 5 day average as advocated here. This enables assessment of the growth factor over an entire quarantine period. If no new cases are observed over this period, the value is not able to be calculated. The dashed vertical lines indicate the day most state borders were closed.

The current 14 day growth factor is 0.95 which gives some degree of confidence that the spread of infections is relatively under control.

Testing Within Each State

latestAU %>%
  dplyr::select(State, Tested = tested) %>%
  write_tsv(
    glue(
      "tested/tested_{format(dt, '%Y%m%d')}.tsv"
    )
  )
latestAU %>%
  dplyr::select(State, Tested = tested) %>%
  full_join(
    confirmed %>%
      dplyr::filter(
        date == dt,
        Country == "Australia"
      ) %>%
      rename(
        State = `Province/State`
      ) 
  ) %>%
  mutate(
    Tested = case_when(
      is.na(Tested) ~ confirmed,
      Tested < confirmed ~ confirmed,
      !is.na(Tested) ~ Tested
    )
  ) %>%
  left_join(ausPops) %>%
  bind_rows(
    tibble(
      State = "Total",
      Population = sum(.$Population, na.rm = TRUE),
      confirmed = sum(.$confirmed, na.rm = TRUE),
      Tested = sum(.$Tested, na.rm = TRUE)
    )
  ) %>%
  mutate(
    `Tests / '000` = round(1e3 * Tested / Population, 2),
    Positive = confirmed / Tested,
    Negative = 1 - Positive,
    isTotal = grepl("Total", State)
  ) %>%
  dplyr::select(
    State, Population,
    Confirmed = confirmed,
    Tested, 
    contains("000"), 
    ends_with("ive"),
    isTotal
  ) %>%
  arrange(isTotal, desc(`Tests / '000`)) %>%
  dplyr::select(-isTotal) %>%
  dplyr::rename(
    `% Positive Tests` = Positive,
    `% Negative Tests` = Negative
  ) %>%
  mutate_at(
    vars(starts_with("%")), percent, accuracy = 0.01
  ) %>%
  pander(
    justify = "lrrrrrr",
    missing = "",
    caption = glue(
      "*COVID-19 testing scaled by state population size.
      Confirmed cases are assumed to be the tests returning a positive result.
      The current numbers available for some states are a lower limit, and as such, the proportion of the population tested is likely to be higher, as is the proportion of tests returning a negative result.*"
    ),
    emphasize.strong.rows = nrow(.)
  )
COVID-19 testing scaled by state population size. Confirmed cases are assumed to be the tests returning a positive result. The current numbers available for some states are a lower limit, and as such, the proportion of the population tested is likely to be higher, as is the proportion of tests returning a negative result.
State Population Confirmed Tested Tests / ’000 % Positive Tests % Negative Tests
Victoria 6,629,870 20,347 3,628,246 547.3 0.56% 99.44%
New South Wales 8,117,976 4,610 3,538,908 435.9 0.13% 99.87%
South Australia 1,756,494 562 752,756 428.6 0.07% 99.93%
Northern Territory 245,562 60 73,024 297.4 0.08% 99.92%
Australian Capital Territory 428,060 117 122,571 286.3 0.10% 99.90%
Queensland 5,115,451 1,212 1,373,765 268.6 0.09% 99.91%
Tasmania 535,500 230 130,497 243.7 0.18% 99.82%
Western Australia 2,630,557 830 563,757 214.3 0.15% 99.85%
Total 25,459,470 27,968 10,183,524 400 0.27% 99.73%

R Session Information

R version 4.0.3 (2020-10-10)

Platform: x86_64-pc-linux-gnu (64-bit)

locale: LC_CTYPE=C, LC_NUMERIC=C, LC_TIME=C, LC_COLLATE=C, LC_MONETARY=C, LC_MESSAGES=en_AU.UTF-8, LC_PAPER=en_AU.UTF-8, LC_NAME=C, LC_ADDRESS=C, LC_TELEPHONE=C, LC_MEASUREMENT=en_AU.UTF-8 and LC_IDENTIFICATION=C

attached base packages: stats, graphics, grDevices, utils, datasets, methods and base

other attached packages: httr(v.1.4.2), readxl(v.1.3.1), ggfortify(v.0.4.11), QuantTools(v.0.5.7.1), data.table(v.1.13.2), cowplot(v.1.1.0), plotly(v.4.9.2.1), pander(v.0.6.3), RCurl(v.1.98-1.2), rvest(v.0.3.6), xml2(v.1.3.2), jsonlite(v.1.7.1), glue(v.1.4.2), broom(v.0.7.2), ggrepel(v.0.8.2), matrixStats(v.0.57.0), scales(v.1.1.1), lubridate(v.1.7.9), magrittr(v.1.5), forcats(v.0.5.0), stringr(v.1.4.0), dplyr(v.1.0.2), purrr(v.0.3.4), readr(v.1.4.0), tidyr(v.1.1.2), tibble(v.3.0.4), ggplot2(v.3.3.2) and tidyverse(v.1.3.0)

loaded via a namespace (and not attached): Rcpp(v.1.0.5), here(v.0.1), rprojroot(v.1.3-2), assertthat(v.0.2.1), digest(v.0.6.27), R6(v.2.5.0), cellranger(v.1.1.0), backports(v.1.2.0), reprex(v.0.3.0), evaluate(v.0.14), highr(v.0.8), pillar(v.1.4.6), rlang(v.0.4.8), curl(v.4.3), lazyeval(v.0.2.2), rstudioapi(v.0.11), rmarkdown(v.2.5), labeling(v.0.4.2), selectr(v.0.4-2), htmlwidgets(v.1.5.2), munsell(v.0.5.0), compiler(v.4.0.3), modelr(v.0.1.8), xfun(v.0.19), pkgconfig(v.2.0.3), htmltools(v.0.5.0), tidyselect(v.1.1.0), gridExtra(v.2.3), fasttime(v.1.0-2), fansi(v.0.4.1), viridisLite(v.0.3.0), crayon(v.1.3.4), dbplyr(v.2.0.0), withr(v.2.3.0), bitops(v.1.0-6), grid(v.4.0.3), gtable(v.0.3.0), lifecycle(v.0.2.0), DBI(v.1.1.0), cli(v.2.1.0), stringi(v.1.5.3), farver(v.2.0.3), fs(v.1.5.0), ellipsis(v.0.3.1), generics(v.0.1.0), vctrs(v.0.3.4), Cairo(v.1.5-12.2), tools(v.4.0.3), crosstalk(v.1.1.0.1), hms(v.0.5.3), yaml(v.2.2.1), colorspace(v.1.4-1), knitr(v.1.30) and haven(v.2.3.1)